﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Loong.BackgroundJobs
{
    public class BackgroundJobInfoMap : IEntityTypeConfiguration<BackgroundJobInfo>
    {
        public void Configure(EntityTypeBuilder<BackgroundJobInfo> entity)
        {
            entity.Property(e => e.JobType)
                .HasMaxLength(BackgroundJobInfo.MaxJobTypeLength)
                .IsRequired();

            entity.Property(e => e.JobArgs)
                .HasMaxLength(BackgroundJobInfo.MaxJobArgsLength)
                .IsRequired();

            entity.Property(e => e.Cron)
                .IsUnicode(false)
                .HasMaxLength(BackgroundJobInfo.MaxCronLength);

            entity.Property(e => e.NextTryTime)
                .HasColumnType("datetime");

            entity.Property(e => e.LastTryTime)
                .HasColumnType("datetime");

            entity.Property(e => e.EndTryTime)
                .HasColumnType("datetime");

            entity.Property(e => e.LockEndTime)
                .HasColumnType("datetime");

            entity.Property(e => e.CreationTime)
                .HasColumnType("datetime");

            entity.ToTable("BackgroundJob");
        }
    }
}
